rm(list = setdiff(ls(), lsf.str())) 

#Load data 2015
data<-read_dta("Study 1/Original Data/828_Selects2015_PanelRCS_Data_v1.1.dta")

#Conscientiousness
data$con1<-car::recode(data$W3_f15770a, "99=NA")
data$con2_rec<-10-car::recode(data$W3_f15770g, "99=NA")
data$con3<-car::recode(data$W3_f15771c, "99=NA")
data$con<-rowMeans(data.frame(data$con1, data$con2_rec, data$con3), na.rm=T)

#Extraversion
data$ext1<-car::recode(data$W3_f15770b, "99=NA")
data$ext2<-car::recode(data$W3_f15770h, "99=NA")
data$ext3_rec<-10-car::recode(data$W3_f15771d, "99=NA")
data$ext<-rowMeans(data.frame(data$ext1, data$ext2, data$ext3_rec), na.rm=T)

#Agreeableness
data$agr1_rec<-10-car::recode(data$W3_f15770c, "99=NA")
data$agr2<-car::recode(data$W3_f15770f, "99=NA")
data$agr3<-car::recode(data$W3_f15771e, "99=NA")
data$agre<-rowMeans(data.frame(data$agr1_rec, data$agr2, data$agr3), na.rm=T)

#Openness
data$open1<-car::recode(data$W3_f15770d, "99=NA")
data$open2<-car::recode(data$W3_f15771a, "99=NA")
data$open3<-car::recode(data$W3_f15771f, "99=NA")
data$open<-rowMeans(data.frame(data$open1, data$open2, data$open3), na.rm=T)

#Neuroticism
data$neu1<-car::recode(data$W3_f15770e, "99=NA")
data$neu2<-car::recode(data$W3_f15771b, "99=NA")
data$neu3_rec<-10-car::recode(data$W3_f15771g, "99=NA")
data$neu<-rowMeans(data.frame(data$neu1, data$neu2, data$neu3_rec), na.rm=T)

#vote choice
data$vote_svp<-ifelse(data$W3_f11800main7==1,1,0)

#sex
data$female<-ifelse(data$sex==2,1,0)

#age
data$age<-car::recode(data$age, "999=NA")

#education
data$education<-car::recode(data$f21310, "99=NA; 1=3; 2=3")
data$education<-data$education-2

#income
data$income<-car::recode(data$f28910, "99=NA")
data$income<-zero1(data$income)
data$income[is.na(data$income)==TRUE]=2
data$income_missing<-ifelse(data$income==2,1,0)

#language
data$language<-data$W3_spr

#Economic conservatism
data$econ_socialspending<-car::recode(data$f15340c, "9=NA") # Opinion on social expenses: strong in favor vs. strong opposed

#social con
data$social_limit_immi<-6-(car::recode(data$f15340b, "9=NA; 8=NA"))

data<-data[complete.cases(data$agre), ]
data<-data[complete.cases(data$social_limit_immi), ]
data<-data[complete.cases(data$econ_socialspending), ]

#participation
data$didnotvote<- ifelse(data$W3_f11100>3, 0,1)

#Popuslit, other, did not vote
data$populist_other_not<- data$vote_svp
data$populist_other_not[data$didnotvote==1]=2

# Other
data$language1<-ifelse(data$W3_spr==1,1,0)
data$language2<-ifelse(data$W3_spr==2,1,0)
data$language3<-ifelse(data$W3_spr==3,1,0)

data$edu1<-ifelse(data$education==1,1,0)
data$edu2<-ifelse(data$education==2,1,0)
data$edu3<-ifelse(data$education==3,1,0)
data$edu4<-ifelse(data$education==4,1,0)
data$edu5<-ifelse(data$education==5,1,0)
data$edu6<-ifelse(data$education==6,1,0)
data$edu7<-ifelse(data$education==7,1,0)
data$edu8<-ifelse(data$education==8,1,0)
data$edu9<-ifelse(data$education==9,1,0)
data$edu10<-ifelse(data$education==10,1,0)
data$edu11<-ifelse(data$education==11,1,0)
data$edu12<-ifelse(data$education==12,1,0)


save(data, file="Study 1/Altered Data/Study1_Swiss_Elections15.RData")
